package com.haocang.szgm.ui.user.activity;

import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.haocang.commonlib.otherutil.ActivityFunctionUnit;
import com.haocang.szgm.R;
import com.haocang.szgm.activity.comm.CommFinalActivity;
import com.haocang.szgm.activity.tool.CacheActivityUtil;

import net.tsz.afinal.annotation.view.ViewInject;

public class AppInfoActivity extends CommFinalActivity implements ActivityFunctionUnit {

    @ViewInject(id = R.id.tv_appname)
    TextView tv_appname;
    @ViewInject(id = R.id.tv_appunit)
    TextView tv_appunit;
    @ViewInject(id = R.id.tv_appcode)
    TextView tv_appcode;

    private Context context;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        context = AppInfoActivity.this;
        //添加到栈
        if (!CacheActivityUtil.activityList.contains(context)) {
            CacheActivityUtil.addActivity(AppInfoActivity.this);
        }

        initView();
        initEvent();
        initData();
    }


    @Override
    protected int getLayoutResourceId() {
        return R.layout.activity_app_info;
    }

    @Override
    protected boolean showNavigation() {
        return true;
    }

    @Override
    protected int showMoreIcon() {
        return 0;
    }

    @Override
    protected String showTitleName() {
        return "关于";
    }


    @Override
    public void initView() {


        PackageManager manager = context.getPackageManager();
        try {
            PackageInfo info = manager.getPackageInfo(context.getPackageName(), 0);
            tv_appcode.setText("V"+info.versionName);
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }

    }

    @Override
    public void initEvent() {

        iv_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
                overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
            }
        });

    }

    @Override
    public void initData() {

    }





    //退出程序
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            finish();
            overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
            return super.onKeyDown(keyCode, event);
        } else {
            return false;
        }
    }

}
